import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gameplay_flutter/lib_basemodel/user/user.dart';
import 'package:gameplay_flutter/lib_runtime/extension/string_extension/string_text.dart';
import 'package:gameplay_flutter/lib_user/user_manager.dart';
import 'package:gameplay_flutter/m_room/constants/room_assets.dart';
import 'package:ones/ui.dart';

import '../model/Room_mic_model.dart';
import '../room_controller/room_controller.dart';
import '../room_controller/room_stateless_controller_mixin.dart';

class RoomMic extends StatelessWidget
    with StatelessControllerMixin<RoomController> {
  final RoomMicModel roomMicModel;

  const RoomMic({Key? key, required this.roomMicModel}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    RoomController roomController = getRoomController(context);

    User? user = roomMicModel.micUser;
    debugPrint("mic ------ ${roomMicModel.toJson()}");
    String headPortraitsUrl = user?.headPortraitsUrl ?? "";
    String name = user?.nickname ?? "Gentle";
    return Column(children: [
      Stack(
        alignment: Alignment.center,
        children: [
          CircleAvatar(
            radius: 24.r,
            backgroundColor: Colors.transparent,
            backgroundImage: headPortraitsUrl.isNotEmpty
                ? CachedNetworkImageProvider(user?.headPortraitsUrl ?? '')
                : const AssetImage(RoomAssets.roomMicEmpty),
          ),
          SizedBox(
            width: 60.w,
            height: 60.h,
          ),
          Stack(
            children: [
              SizedBox(
                width: 48.w,
                height: 48.h,
              ),
              PositionedDirectional(
                  bottom: 0,
                  end: 0,
                  child: Image.asset(
                    RoomAssets.roomMicOpen,
                    width: 18.w,
                    height: 18.h,
                  ))
            ],
          ),
        ],
      ),
      name .text(
        fontSize: 11.sp,
        color: Colors.white,
        weight: TextFontWeight.bold,
      ),
    ]).onClick(() {
      if (roomMicModel.micUser == null) {
        String userId = UserManager.instance.id.toString();
        roomController.holdUp(userId, roomMicModel.index!);
      }
    });
  }
}
